﻿Imports System.Management

Public Class FrmMain

    Private Sub LstProfiles_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LstProfiles.SelectedIndexChanged

        Dim WQLQuery As WqlObjectQuery
        Dim Searcher As ManagementObjectSearcher
        Dim Adapter As ManagementObject
        Dim NewTab As TabPage
        Dim LViewItem As ListViewItem
        Dim Ctrl As CtrlAdapter

        WQLQuery = New WqlObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE manufacturer<>'Microsoft'")
        Searcher = New ManagementObjectSearcher(WQLQuery)



        For Each Adapter In Searcher.Get()
            Ctrl = New CtrlAdapter
            LViewItem = New ListViewItem
            LViewItem.Text = Adapter.Properties("Description").Value

            Ctrl.LblAdapterNameValue.Text = Adapter.Properties("Description").Value
            Ctrl.LblAdapterManufacturerValue.Text = Adapter.Properties("Manufacturer").Value


            Select Case Adapter.Properties("AdapterTypeID").Value
                Case 0
                    Ctrl.LblAdapterTypeValue.Text = "Ethernet 802.3"
                Case 1
                    Ctrl.LblAdapterTypeValue.Text = "Token Ring 802.5"
                Case 2
                    Ctrl.LblAdapterTypeValue.Text = "Fiber Distributed Data Interface (FDDI)"
                Case 3
                    Ctrl.LblAdapterTypeValue.Text = "Wide Area Network (WAN)"
                Case 4
                    Ctrl.LblAdapterTypeValue.Text = "LocalTalk"
                Case 5
                    Ctrl.LblAdapterTypeValue.Text = "Ethernet using DIX header format"
                Case 6
                    Ctrl.LblAdapterTypeValue.Text = "ARCNET"
                Case 7
                    Ctrl.LblAdapterTypeValue.Text = "ARCNET (878.2)"
                Case 8
                    Ctrl.LblAdapterTypeValue.Text = "ATM"
                Case 9
                    Ctrl.LblAdapterTypeValue.Text = "Wireless"
                Case 10
                    Ctrl.LblAdapterTypeValue.Text = "Infrared Wireless"
                Case 11
                    Ctrl.LblAdapterTypeValue.Text = "Bpc"
                Case 12
                    Ctrl.LblAdapterTypeValue.Text = "CoWan"
                Case 13
                    Ctrl.LblAdapterTypeValue.Text = "1394"
                Case Else
                    Ctrl.LblAdapterTypeValue.Text = "Unknown adapter type [" & Adapter.Properties("AdapterTypeID").Value & "]"
            End Select
            LViewItem.SubItems.Add(Ctrl.LblAdapterTypeValue.Text)
            Try
                LViewItem.SubItems.Add(Adapter.Properties("Manufacturer").Value)
            Catch ex As Exception
                LViewItem.SubItems.Add("No manufacturer information")
            End Try

            LViewAdapter.Items.Add(LViewItem)


            NewTab = New TabPage
            NewTab.Text = Adapter.Properties("Description").Value
            TabSettings.TabPages.Add(NewTab)
            NewTab.Controls.Add(Ctrl)
        Next
    End Sub

    Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
        LstProfiles.Items.Add("One")
        LstProfiles.Items.Add("Two")

        Dim ColAdapter As New Collection
        Dim CMnuTrayicon As New ContextMenu
        Dim Tray As New NotifyIcon
        Dim MnuAdapter As MenuItem
        Dim CurrentAdapter As MenuItem
        Dim NewItem As MenuItem

        Tray.ContextMenu = CMnuTrayicon
        NewItem = New MenuItem
        NewItem.Text = "Adapters"
        NewItem.Enabled = False
        CMnuTrayicon.MenuItems.Add(NewItem)

        ColAdapter = ClsAdapter.getAdapter
        For Each adapter As ClsAdapter In ColAdapter
            CurrentAdapter = CMnuTrayicon.MenuItems.Add(adapter.Name)
            CurrentAdapter.MenuItems.Add("Properties")
            NewItem = New MenuItem
            NewItem.Text = "Manufacturer: " & adapter.Manufacturer
            NewItem.Enabled = False
            CurrentAdapter.MenuItems.Add(NewItem)

            NewItem = New MenuItem
            NewItem.Text = "Type: " & ClsAdapter.getTypeName(adapter.TypeId)
            NewItem.Enabled = False
            CurrentAdapter.MenuItems.Add(NewItem)

            NewItem = New MenuItem
            NewItem.Text = "Enabled: " & adapter.Enabled
            NewItem.Enabled = False
            CurrentAdapter.MenuItems.Add(NewItem)

            CurrentAdapter.MenuItems.Add("-")
            NewItem = New MenuItem
            NewItem.Text = "Functions"
            NewItem.Enabled = False
            CurrentAdapter.MenuItems.Add(NewItem)

            CurrentAdapter.MenuItems.Add("Enable")
        Next
        CMnuTrayicon.MenuItems.Add("-")
        CMnuTrayicon.MenuItems.Add("Exit")
        Tray.Icon = Me.Icon
        Tray.Visible = True
        
    End Sub
End Class
